package com.zhiyou100.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.mapper.CourseMapper;
import com.zhiyou100.mapper.VideoMapper;
import com.zhiyou100.model.Course;
import com.zhiyou100.model.Subject;
import com.zhiyou100.model.Video;
import com.zhiyou100.service.CourseService;
@Service
public class CourseServiceImpl implements CourseService{
	@Autowired
	private CourseMapper cm;
	
	@Override
	public Course selectCourse(Integer id) {
		// TODO Auto-generated method stub
		return cm.selectCourse(id);
	}
	
	@Override
	public PageInfo<Course> selectCourseAll(Integer pageNum,Integer pageSize) {
		if(pageNum==null) {
			pageNum = 1;
		}
		
		PageHelper.startPage(pageNum, pageSize);
		List<Course> courses = cm.selectCourseAll();
		for (Course course : courses) {
			Subject subject = course.getSubject();
		}
	
		PageInfo<Course> pageInfo = new PageInfo<>(courses);
		return pageInfo;
	}

	@Override
	public List<Course> selectCourses() {
		
		return cm.selectCourseAll();
	}

	@Override
	public int updateCourse(Course course) {
		
		return cm.updateCourse(course);
	}

	@Override
	public int addCourse(Course course) {
		
		return cm.addCourse(course);
	}

	@Override
	public int deleteCourse(Integer id) {
		// TODO Auto-generated method stub
		return cm.deleteCourse(id);
	}

	@Override
	public List<Course> selectCourseAndVideo() {
		List<Course> courses = cm.selectCourseAndVideo();
		for (Course course : courses) {
			List<Video> video = course.getVideo();
		}
		return courses;
	}

}
